<?php

function __autoload($class)
{
	include_once $class . '.php';
}



$angel1 = new Angel("sofia", 22, "Angel 1");
$angel2 = new Angel("sofia", 23, "Angel 2");
$angel3 = new Angel("sofia", 25, "Angel 3");
$angel4 = new Angel("sofia", 26, "Angel 4");
$angel5 = new Angel("sofia", 27, "Angel 5");
$angel6 = new Angel("sofia", 28, "Angel 6");

$dobri = new Dobri("Dobri", 25);
$array = array($angel1, $angel2, $angel3, $angel4, $dobri, $angel5, $angel6);

$cheren_petar = "";
$count = count($array);
for($i = 1; $i < $count; $i++){
	$class_name_prev = get_class($array[$i-1]);
	$class_name_next = get_class($array[$i]);
	if(isset($check1)){
		if($class_name_next == $check1){
			$cheren_petar = $array[$i-1];
			unset($array[$i-1], $array);
			break;
		}
		else{
			$cheren_petar = $array[$i-2];
			unset($array, $array[$i-2]);
			break;
		}
	}
	if(!($class_name_prev == $class_name_next)){
		$check1 = $class_name_prev;
		$check2 = $class_name_next;
	}
}

var_dump($cheren_petar);

?>